package Client;

import Server.Domain.Message;
import Server.Domain.User;
import Utility.Scan;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class LogCheck {
    Message message = new Message();

    public boolean logIn(Socket socket,User user) {
        System.out.print("请输入用户名:");
        user.setName(Scan.read());
        System.out.print("请输入密码:");
        user.setPassword(Scan.read());
        System.out.println("正在登录中...");
        try {
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(user);
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            Message messageBack = (Message) ois.readObject();
            if (messageBack.getMessageType().getValue() == 1) {
                return true;
            } else {
                System.out.println("登录失败,请重试");
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

}
